package nio.nio.zeroCopy;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @author 帅小伙
 * @date 2022/1/15
 * @description
 */
public class NewIOClient {

    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost",7001));
        String fileName = "file1.txt";

        FileChannel fileChannel = new FileInputStream(fileName).getChannel();

         // windows  一次 transferTo 一次只能8m
        long l = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println("发送总的字节数"+l);
    }
}
